﻿<!DOCTYPE html>
<html class="L_UI">
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="/CSS/Main.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="/Content/lib/iview/styles/iview.css">
</head>
<body>
    <div class="Window" style="min-width: 1100px;" id="app">
        <div class="Header" style="height:116px;">
            <table border="0" cellpadding="0" cellspacing="0" width="100%" class="table">
                <tr>
                    <td style="width: 7%; text-align: right; padding-right: 5px;">
                        公&nbsp;&nbsp;&nbsp;&nbsp;司：
                    </td>
                    <td style="width: 20%; text-align: left; padding-left: 10px;">
                        <thk-company v-model="FORM_COMPANY_ID"></thk-company>
                    </td>
                    <td style="width: 7%; text-align: right; padding-right: 5px;">
                        是否匹配：
                    </td>
                    <td style="width: 15%; text-align: left; padding-left: 10px;">
                        <select class="INPUT" v-model="FORM_IF_CHECK">
                            <option value="-1">--请选择--</option>
                            <option value="0">未匹配</option>
                            <option value="1">已匹配</option>
                        </select>
                    </td>
                    <td style="width: 7%; text-align: right; padding-right: 5px;">
                        具体日期：
                    </td>
                    <td style="text-align: left; padding: 5px;">
                        <template>
                            <thk-datepick :placeholder="'开始时间'" v-model="FORM_BEGIN_DATE" />
                        </template>

                        至
                        <template>
                            <thk-datepick :placeholder="'结束时间'" v-model="FORM_END_DATE" />
                        </template>
                    </td>
                </tr>
                <tr>
                    <td style="width: 7%; text-align: right; padding-right: 5px;">客户公司：</td>
                    <td style="width: 20%; text-align: left; padding-left: 10px;">
                        <input type="text" placeholder="公司名称，简写" class="INPUT" v-model="FORM_CUSTEMER_TEXT" />
                    </td>
                    <td style="width: 7%; text-align: right; padding-right: 5px;">对方账号：</td>
                    <td style="width: 20%; text-align: left; padding-left: 10px;">
                        <input type="text" placeholder="对方账号，简写" class="INPUT" v-model="FORM_CUSTEMER_ACCOUNT_TEXT" />
                    </td>
                    <td colspan="2" style="text-align: left; ">
                        <span>
                            <input type="checkbox" v-model="FORM_POOL_VALUE" />
                            ：资金池
                        </span>
                        <span>
                            <input type="checkbox" v-model="FORM_DELETE_VALUE" />
                            ：删除项
                        </span>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="6" >
                        <button type="button" class="bt_css_s" @click="SELECT(true)">查询</button>
                        <button type="button" class="bt_css_s" @click="AUTO_MATCHING">自动匹配</button>
                    </td>
                </tr>
            </table>
        </div>
        <div class="Content" style="top:118px;">
            <div ref="TABLE_PANLE" class="Pg-Content" style="bottom:40px;">
                <i-Table :loading="FORM_DATA.LODING" @on-sort-change="SORT_CHANG" size="small" border :columns="FORM_DATA.COLUMNS" :data="FORM_DATA.DATA" :height="FORM_DATA.HEIGHT">
                </i-Table>
            </div>
            <div class="Pg" style="text-align:center;height:40px;padding:4px 0;">
                <template>
                    <Page show-sizer :total="FORM_DATA.TOTAL" :page-size="FORM_DATA.PAGE_SIZE" :current="FORM_DATA.CURRENT_PAGE" @on-page-size-change="PAGE_SIZE_CHANG" @on-change="PAGE_CHANGE" />
                </template>
            </div>
        </div>
    </div>
    <script src="/UserCotrols/My97DatePicker/WdatePicker.js"></script>
    <script src="/Content/lib/vue/vue-2.5.17.min.js"></script>
    <script src="/Content/lib/axios/axios.js"></script>
    <script type="text/javascript" src="/Content/lib/iview/iview.min.js"></script>
    <script src="/Scripts/jquery.1.11.1.js"></script>
    <script src="/Scripts/Thk.Utility.js"></script>
    <script src="/Scripts/Thk.Component.js"></script>
    <script type="text/javascript">
        //构造Web程序入口
        var app = new Vue({
            el: "#app",
            data: {
                FORM_BEGIN_DATE: null,
                FORM_END_DATE: null,
                FORM_COMPANY_ID: -1,
                FORM_POOL_VALUE: false,
                FORM_CUSTEMER_TEXT: "",
                FORM_CUSTEMER_ACCOUNT_TEXT: "",
                FORM_IF_CHECK: -1,
                FORM_DELETE_VALUE: false,
                FORM_DATA: {
                    HEIGHT:400,
                    COLUMNS: [
                        {
                            type: 'index',
                            title: "序号",
                            align: "center",
                            width: 60
                        },
                        {
                            title: "匹配日期",
                            key: "D_TRANDATE",
                            width: 105,
                            align: "center",
                            render: function (h, params) {
                                //console.log(params);
                                var date = new Date(params.row.D_TRANDATE);
                                //console.log(params.row.D_TRANDATE);
                                return h('div', date.format("yyyy-MM-dd"));
                            },
                            sortable: true
                        },
                        {
                            title: "账号",
                            key: "C_ACCNO1",
                            minWidth: 200,
                            tooltip: true,
                            sortable: true
                        }
                        ,
                        {
                            title: "对方账号",
                            key: "C_ACCNO2",
                            minWidth: 200,
                            tooltip: true,
                            sortable: true
                        }
                        ,
                        {
                            title: "对方账号名称",
                            key: "C_ACC_NAME1",
                            minWidth: 200,
                            tooltip: true,
                            sortable: true
                        },
                        {
                            title: "客户公司",
                            key: "CUSTER_NAME",
                            minWidth: 200,
                            tooltip: true,
                            sortable: true
                        }

                        ,
                        {
                            title: "用气类型",
                            key: "CUSTOMER_TYPE",
                            minWidth: 105,
                            tooltip: true,
                            sortable: true
                        }
                        ,
                        {
                            title: "发生额",
                            key: "N_AMT",
                            minWidth: 100,
                            tooltip: true,
                            align: "right",
                            sortable: true
                        }
                        ,
                        {
                            title: "借贷标志",
                            key: "FLAG_MSG",
                            width: 105,
                            tooltip: true,
                            align: "center",
                            sortable: true
                        }

                        ,
                        {
                            title: "是否匹配",
                            key: "N_STATE",
                            width: 80,
                            align: "center",
                            render: function (h, params) {
                                switch (params.row.N_STATE) {
                                    case 1:
                                        {
                                            return h("div", "已匹配");
                                        }
                                        break;
                                    case 0:
                                        {
                                            return h("div", "未匹配");
                                        }
                                    default:
                                }

                            },
                            tooltip: true,
                            sortable: true

                        }
                        ,
                        {
                            title: "备注",
                            key: "C_DET",
                            minWidth: 100,
                            tooltip: true,
                            sortable: true
                        }
                        ,
                        {
                            title: "所属计划周",
                            key: "USE_WEEK",
                            align:"center",
                            width: 100,
                            sortable: true
                        },
                        {
                            title: '操作',

                            width: 130,
                            align: 'center',
                            fixed: "right",
                            sortable: true,
                            render: (h, params) => {
                                if (params.row.N_IF_DELETE == 1) {

                                    return h("div", "已删除");
                                }
                                switch (params.row.N_STATE) {
                                    case 1:
                                        {
                                            return h('div', [
                                                h('Button', {
                                                    props: {
                                                        type: 'error',
                                                        size: 'small'
                                                    },
                                                    style: {
                                                        marginRight: '5px'
                                                    },
                                                    on: {
                                                        click: () => {
                                                            window.App.REFUND(params.row);
                                                        }
                                                    }
                                                }, '退款')
                                            ]);
                                        }
                                        break;
                                    case 0:
                                        {
                                            return h('div', [
                                                h('Button', {
                                                    props: {
                                                        type: 'primary',
                                                        size: 'small'
                                                    },
                                                    style: {
                                                        marginRight: '5px'
                                                    },
                                                    on: {
                                                        click: () => {
                                                            var option = {};
                                                            option.Area = ["880px", "460px"];
                                                            option.Title = "1";
                                                            option.Url = "/Funds/BankListEdit.aspx?ID=" + params.row.N_DETAIL_LISTID.toString();
                                                            option.Title = "修改银行流水信息";
                                                            top.MessageBox.Load(option);
                                                            //top.layer.open();
                                                            //this.show(params.index)
                                                        }
                                                    }
                                                }, '修改'),
                                                h('Button', {
                                                    props: {
                                                        type: 'primary',
                                                        size: 'small'
                                                    },
                                                    style: {
                                                        marginRight: '5px'
                                                    },
                                                    on: {
                                                        click: () => {
                                                            $.ajax({
                                                                type:"POST",
                                                                async: false,
                                                                url: "/Funds/BankListSet.aspx?TYPE=API",
                                                                data: JSON.stringify({ Type: "DELETE", ID: params.row.N_DETAIL_LISTID }),
                                                                success: function (result) {
                                                                    params.row.N_IF_DELETE = 1;
                                                                }
                                                            });
                                                        }
                                                    }
                                                }, '删除')
                                            ]);
                                        }
                                        break;
                                    default:
                                }

                            }
                        }
                    ],
                    DATA: [],
                    CURRENT_PAGE: 1,
                    TOTAL: 100,
                    PAGE_SIZE: 40,
                    LODING: true,
                    WhereStr: ""
                }
            },
            methods: {
                SELECT: function (ifFirst) {
                    var that = this;
                    that.FORM_DATA.LODING = true;
                    if (ifFirst) {
                        that.FORM_DATA.CURRENT_PAGE = 1;
                        that.WhereStr = "";
                        if (that.FORM_IF_CHECK != -1) {
                            that.WhereStr += " AND T1.N_STATE=" + that.FORM_IF_CHECK;
                        }
                        console.log(that.FORM_COMPANY_ID);
                        if (that.FORM_COMPANY_ID!=-1) {
                            that.WhereStr += " and T1.N_COMPANY_ID=" + that.FORM_COMPANY_ID;
                        }
                        else {

                            that.WhereStr += " and T1.N_COMPANY_ID in (select cp.cmy_id from sys_company cp start with cp.cmy_id = " + top.LoginUser.USER_COMPANY;
                            that.WhereStr +="connect by prior cp.cmy_id = cp.cmy_parentid)";
                        }
                        if (that.FORM_BEGIN_DATE != null) {
                            that.WhereStr += " AND TRUNC(T1.d_trandate) >= TO_DATE('" + that.FORM_BEGIN_DATE.format("yyyy-MM-dd")+"','YYYY-MM-DD')";
                        }
                        if (that.FORM_END_DATE != null) {
                            that.WhereStr += " AND TRUNC(T1.d_trandate) <= TO_DATE('" + that.FORM_END_DATE.format("yyyy-MM-dd") + "','YYYY-MM-DD')";
                        }
                        if (that.FORM_CUSTEMER_TEXT.trim()!="") {
                            that.WhereStr += " and T1.C_ACC_NAME1 like '%" + that.FORM_CUSTEMER_TEXT.trim() + "%'";
                        }
                        if (that.FORM_CUSTEMER_ACCOUNT_TEXT.trim() != "") {
                            that.WhereStr += " and T1.C_ACCNO2 like '%" + that.FORM_CUSTEMER_ACCOUNT_TEXT.trim() + "%'";
                        }
                        if (!that.FORM_DELETE_VALUE) {
                            that.WhereStr += " and T1.N_IF_DELETE != 1";
                        }
                        //资金池
                        console.log(that.FORM_POOL_VALUE);
                        if (!that.FORM_POOL_VALUE) {
                            that.WhereStr  += " and T1.C_DET != '资金池'";
                        }
                        console.log(that.WhereStr);

                    }
                    //拼接条件
                    var data = {};
                    data.IfFirst = ifFirst;
                    data.WhereStr = that.WhereStr;

                    console.log(that.FORM_BEGIN_DATE);
                    data.SortStr = "T1.D_TRANDATE ASC";
                    data.PageSize = that.FORM_DATA.PAGE_SIZE;
                    data.CurrentPage = that.FORM_DATA.CURRENT_PAGE;

                    axios.post("/Funds/BankListSet.aspx?TYPE=API", JSON.stringify(data))
                        .then(result => {
                            if (result.status != 200) {

                                return;
                            }
                            var data = result.data;
                            that.FORM_DATA.DATA = data.Data.Data;
                            //console.log(data.Data);
                            //console.log(Math.ceil(data.Data.Count / 50));
                            that.FORM_DATA.TOTAL = data.Data.Count;
                            that.FORM_DATA.LODING = false;
                    });
                },
                PAGE_SIZE_CHANG: function (size) {
                    //this.FORM_DATA.CURRENT_PAGE = size;
                    //this.SELECT(false);
                    this.FORM_DATA.PAGE_SIZE = size;
                    this.SELECT(true);
                },
                PAGE_CHANGE: function (size) {
                    this.FORM_DATA.CURRENT_PAGE = size;
                    this.SELECT(false);
                },
                SORT_CHANG: function (column, key, order) {

                },
                REFUND(item) {
                    //REFUND
                    var that = this;
                    //拼接条件
                    var data = {};
                    data.Type = "REFUND";
                    data.BankId = item.N_DETAIL_LISTID;

                    axios.post("/Funds/BankListSet.aspx?TYPE=API", JSON.stringify(data))
                        .then(result => {
                            if (result.status != 200) {

                                that.$Modal.info({
                                    title: '提示',
                                    content: `服务异常`
                                });
                                return;
                            }
                            var data = result.data;
                            if (data.Type==1) {
                                that.$Modal.info({
                                    title: '提示',
                                    content: `退款成功`
                                });
                                item.N_STATE = 0;
                            }
                            else {
                                that.$Modal.info({
                                    title: '提示',
                                    content: `退款失败`
                                });
                            };
                        });

                },
                AUTO_MATCHING: function () {
                    var that = this;
                    //拼接条件
                    var data = {};
                    data.Type = "AUTO_MATCHING";
                    axios.post("/Funds/BankListSet.aspx?TYPE=API", JSON.stringify(data))
                        .then(result => {
                            if (result.status != 200) {

                                that.$Modal.info({
                                    title: '提示',
                                    content: `服务异常`
                                });
                                return;
                            }
                            var data = result.data;
                            if (data.Type == 1) {
                                that.SELECT(true);
                                that.$Modal.info({
                                    title: '提示',
                                    content: `自动匹配成功`
                                });
                            }
                            else {
                                that.$Modal.info({
                                    title: '提示',
                                    content: `退款失败`
                                });
                            };
                        });
                }
            },
            mounted: function () {
                var that = this;
                window.App = that;
                that.FORM_DATA.HEIGHT = that.$refs.TABLE_PANLE.scrollHeight;

                that.SELECT(true);
                window.onresize = function () {
                    that.FORM_DATA.HEIGHT = that.$refs.TABLE_PANLE.scrollHeight;
                };
            }
        });
    </script>
</body>
</html>